package com.zzh.custom.refresh;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.zzh.custom.R;

public class DefaultHead extends Head {
    private static final String TAG = "content";

    private View mRootView;

    private float mDownY;
    private float mDownX;


    @Override
    public View createView(ViewGroup parent) {
        mRootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.zzh_refresh_head, parent, false);
        return mRootView;
    }

    @Override
    public void init() {

    }


    @Override
    void onTouchDown(MotionEvent ev, int height, int width) {
        mDownX = ev.getX();
        mDownY = ev.getY();
    }

    @Override
    void onTouchMove(MotionEvent ev, int height, int width) {
        Log.i(TAG, "onTouchMove: " + ev.getY() +">>>" + mDownY);
        ((LinearLayout.LayoutParams) mRootView.getLayoutParams()).topMargin = -height + ((int) (ev.getY() - mDownY ));
        mRootView.requestLayout();
    }

    @Override
    void onTouchUp(MotionEvent ev, int height, int width) {
        ((LinearLayout.LayoutParams) mRootView.getLayoutParams()).topMargin = -height;
        mRootView.requestLayout();
    }
}
